feat(client): add SUNIONCARD and SDIFFCARD set cardinality commands#3336
Open
nkaradzhov wants to merge 2 commits into
Open
feat(client): add SUNIONCARD and SDIFFCARD set cardinality commands#3336nkaradzhov wants to merge 2 commits into
nkaradzhov wants to merge 2 commits into
Conversation
Add read-only cardinality commands for derived set operations. SUNIONCARD numkeys key [key ...] [APPROX] [LIMIT limit] returns the distinct-element count of the union; supports exact mode (default), optional APPROX (HyperLogLog), and optional LIMIT (LIMIT 0 = no limit), emitted in canonical order APPROX before LIMIT. SDIFFCARD numkeys key [key ...] [LIMIT limit] returns the element count of the difference between the first set and all successive sets. APPROX is not exposed (out of scope until server semantics are defined). Both use pushKeysLength for the numkeys-prefixed key list, are flagged IS_READ_ONLY, return a NumberReply, and propagate server errors as-is. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Add isVersionGreaterThanHook([8, 10]) so integration tests skip on pre-8.10 servers instead of failing with unknown-command errors. - Add @see links and "Added since Redis 8.10." to the registry entries, matching the surrounding set-command convention. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for the Redis 8.10 set cardinality commands
SUNIONCARDandSDIFFCARD.Both commands compute the cardinality of a derived set operation in a single read-only command without materializing or returning the derived set:
SUNIONCARD numkeys key [key ...] [APPROX] [LIMIT limit]— distinct-element count of the union of the given sets. Supports exact mode (default), optionalAPPROX(HyperLogLog estimate), and optionalLIMITcap (LIMIT 0= no limit). Options emitted in canonical orderAPPROXbeforeLIMIT.SDIFFCARD numkeys key [key ...] [LIMIT limit]— element count of the difference between the first set and all successive sets. Exact mode with optionalLIMIT.APPROXis intentionally not exposed (out of scope until server semantics are defined; the server rejects it with a syntax error).Both use
pushKeysLengthfor thenumkeys-prefixed key list, are flaggedIS_READ_ONLY, and return aNumberReply. Server errors propagate unchanged; no client-side validation is added. Registered under raw (SUNIONCARD/SDIFFCARD) and camelCase (sUnionCard/sDiffCard) names.Behavior considerations: exact
LIMITreturnsmin(realCardinality, limit);APPROXresults are approximate integers not exceedinglimit. No backward-compatibility risk — new commands only.🤖 Generated with Claude Code
Note
Low Risk
Additive read-only command definitions mirroring SINTERCARD; no changes to existing behavior.
Overview
Adds Redis 8.10 client support for
SUNIONCARDandSDIFFCARD, read-only commands that return set union or set-difference cardinality without materializing members.Each command is implemented with
pushKeysLength,IS_READ_ONLY, and aNumberReply.SUNIONCARDaccepts optionalAPPROX(HyperLogLog) andLIMIT(emitted asAPPROXthenLIMIT).SDIFFCARDonly exposesLIMIT;APPROXis not wired on the client. Both are registered in the command index as raw and camelCase (sUnionCard/sDiffCard). Specs cover argument encoding and integration tests gated on Redis ≥ 8.10.Reviewed by Cursor Bugbot for commit 105ce3f. Bugbot is set up for automated code reviews on this repo. Configure here.